package com.lgx.mall.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import net.sf.json.JSONObject;

import com.lgx.common.entity.IdGenerator;
import com.lgx.common.web.util.DateUtils;
import com.lgx.common.web.util.DictUtils;

/**
 * 积分卡
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name="TM_SCORECARD")
public class ScoreCard implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator=IdGenerator.SCORECARD_ID_GENERATOR)
	@TableGenerator(
			name = IdGenerator.SCORECARD_ID_GENERATOR,
			table = IdGenerator.GENERATOR_TABLE,
			pkColumnName = IdGenerator.GEN_NAME,
			pkColumnValue = IdGenerator.SCORECARD_ID_GENERATOR,
			valueColumnName = IdGenerator.GEN_VALUE,
			initialValue = 1,
			allocationSize = 1
	)
	private long id;
	
	/**
	 * 卡号
	 */
	private String card;
	
	/**
	 * 密码
	 */
	private String password;
	
	/**
	 * 积分
	 */
	private Double score;
	
	/**
	 * 是否可用 0可用，1已用
	 * 1=不可用
	 * 0=可用
	 */
	private String isDelete;
	
	/**
	 * 是否锁定 true锁定，false未锁
	 * 1=锁定
	 * 0=未锁定
	 */
	private Boolean locked;
	
	/**
	 * 有效起始时间
	 */
	private Date effectiveTimeStart;
	
	/**
	 * 有效结束时间
	 */
	private Date effectiveTimeEnd;
	
	private Date createTime;

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getCard() {
		return card;
	}

	public void setCard(String card) {
		this.card = card;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Double getScore() {
		return score;
	}

	public void setScore(Double score) {
		this.score = score;
	}

	public String getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(String isDelete) {
		this.isDelete = isDelete;
	}

	public Boolean getLocked() {
		return locked;
	}

	public void setLocked(Boolean locked) {
		this.locked = locked;
	}

	public Date getEffectiveTimeStart() {
		return effectiveTimeStart;
	}

	public void setEffectiveTimeStart(Date effectiveTimeStart) {
		this.effectiveTimeStart = effectiveTimeStart;
	}

	public Date getEffectiveTimeEnd() {
		return effectiveTimeEnd;
	}

	public void setEffectiveTimeEnd(Date effectiveTimeEnd) {
		this.effectiveTimeEnd = effectiveTimeEnd;
	}
	
	public String getStatus()
	{
		String status = "";
		
		status = this.getIsDelete().equals("0")?DictUtils.getDictNameByKindAndCode(DictUtils.SCORECARD_STRUT,"1"):DictUtils.getDictNameByKindAndCode(DictUtils.SCORECARD_STRUT,"2");
		status += " | ";
		status += this.getLocked()?DictUtils.getDictNameByKindAndCode(DictUtils.SCORECARD_STRUT,"3"):DictUtils.getDictNameByKindAndCode(DictUtils.SCORECARD_STRUT,"4");
		
		return status;
	}
	
	/**
	 * 用户管理加载页面
	 * 会员管理加载页面
	 */
	@Override
	public String toString() {
		JSONObject obj = new JSONObject();
		
		obj.put("id", this.getId());
		obj.put("card", this.getCard());            //卡号 
		obj.put("password", this.getPassword());    //密码
		obj.put("score", this.getScore());               //积分
		obj.put("status", this.getStatus());             //状态
		obj.put("startime",this.getEffectiveTimeStart()!=null?DateUtils.dateToChar(this.getEffectiveTimeStart(),DateUtils.DATE_FORMAT_D):"");   //起始有效时间
		obj.put("endtimne",this.getEffectiveTimeEnd()!=null?DateUtils.dateToChar(this.getEffectiveTimeEnd(),DateUtils.DATE_FORMAT_D):"");       //结束有效时间,若为空就输入空
		return obj.toString();
	}
}
